package controladores;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dominio.Cliente;
import dominio.PaqueteDeViaje;
import dominio.Reserva;

public class GuardarReservaServlet extends GenericServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
		private Reserva reserva;

	public GuardarReservaServlet() {
		super();
		reserva = new Reserva();
	}

	public void doAction(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(true);
		try {
			Reserva reserva = (Reserva) session.getAttribute("reserva");
			if ( reserva.getPasajeros() != null ) {
				reserva.setFecha(new Date().toString());
				
				if(reserva.getIdReserva() != null){
					reserva.actualizarRegistroBd();
				} else {
					reserva.guardarRegistroBd();
				}

				
				request.getRequestDispatcher("/guardar_reserva.jsp").forward(request, response);
			} else {
				request.getRequestDispatcher("/error_reserva.jsp").forward(request, response);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}  
	}

	

}